import cmsisdsp as dsp
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt

ADC_SIZE=50
SAMPLING_RATE=2400_000

# 模拟信号创建
def creatSignal():
    t=np.arange(0,1,1/1000)
    sig=np.sin(2*np.pi*5*t)
    noise=np.random.normal(loc=0, scale=0.2, size=len(t))
    return sig+noise
# 滑动求和过滤器
def sum_filter(input,dec):
    sum=0
    output=[]
    for i in range(len(input)):
        sum+=input[i]
        if((i+1)%dec==0):
            output.append(sum)
            sum=0
    return output
# NCO数据表创建
def compute_lo(freq):
    lo_i=[]
    lo_q=[]
    for i in range(ADC_SIZE):
        k=2 * np.pi * freq / SAMPLING_RATE
        lo_i.append(np.cos(i*k))
        lo_q.append(np.sin(i*k))
    return lo_i,lo_q
# 测试滑动求和过滤器
def test_sum_filter():
    input=creatSignal()
    output=sum_filter(input,16)

    plt.subplot(2,1,1)
    plt.plot(input)
    plt.subplot(2,1,2)
    plt.plot(output)
    plt.show()
# 测试NCO数据表创建
def test_compute_lo():
    lo_i,lo_q=compute_lo(819e3)
    plt.plot(lo_i)
    plt.plot(lo_q)
    plt.show()

# test_compute_lo()
test_sum_filter()